<?php
//require_once '../ptnhuan-web1/libraries/utilites/functions.php';
$path = "../ptnhuan-web1/data/films.txt";
$file_path = realpath($path);
$rating1 = NULL;
$rating2 = NULL;
$films = array();

$file = fopen($file_path, "r");
while (!feof($file)) {
    $films [] = trim(fgets($file));
}
fclose($file);
?>
<link rel="stylesheet" type="text/css" href="public/css/style.css">
<form method="POST">
    From : <input type="text" name="rating1">
    To :   <input type="text" name="rating2">
    <input type="submit" name="submit" value="Go">
</form>

<?php foreach ($films as $item): ?>
    <?php if (!empty($item)) : ?>
        <?php $film = explode(";", $item) ?> 
        <?php if (isset($_GET['uid'])): ?>
            <?php if ((int) $_GET['uid'] == (int) $film[4]): ?>
                <?php echo $film[0] ?>
                <img src ='../ptnhuan-web1/public/images/films/<?php echo $film[1] ?>'>
                <?php echo $film[2] ?>
                <?php echo $film[3] ?>
                <br>
                <?php
                if (isset($_POST["submit"])) {
                    $rating1 = intval($_POST["rating1"]);
                    $rating2 = intval($_POST["rating2"]);
                }
                ?>
                <?php if (($film[3] >= $rating1) && ($film[3] <= $rating2)): ?>
                    <a href='file_edit.php?if= <?php echo "$film[0]"; ?>'>EDIT</a>
                    <img src ='../ptnhuan-web1/public/images/films/<?php echo $film[1] ?>'>
                    <?php echo $film[2] ?>
                    <?php echo $film[3] ?>
                    <br>
                <?php endif; ?>
            <?php endif; ?>
        <?php endif; ?>
    <?php endif; ?>
<?php endforeach; ?>
